package com.becca.cake.model.goods;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import com.becca.cake.core.exception.ServiceException;

/**
 * 商品表
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年4月10日 上午1:23:15
 */
public class GoodsModel implements Serializable {
    /**  */
    private static final long   serialVersionUID            = -2766995238634303399L;
    /**商品状态(1:已上架)*/
    public static final Byte    GOODS_STATUS_ALREADY        = 1;
    /**商品状态(0:未上架)*/
    public static final Byte    GOODS_STATUS_NOT_ALREADY    = 0;
    /**商品状态(2:已下架)*/
    public static final Byte    GOODS_STATUS_DOWN           = 2;

    /**试吃申请商品数量 默认为1*/
    public static final Integer GOODS_NUMBER_ONE            = 1;
    /**商品类型(0:商品 )*/
    public static final Byte    GOODS_TYPE_DEFALUT          = 0;

    /**商品类型(1:配件 )*/
    public static final Byte    GOODS_TYPE_PARTS            = 1;
    /**商品编号不能为空*/
    public static final String  GOODS_ID_NULL               = "商品编号不能为空";
    /**商品信息不存在*/
    public static final String  GOODS_NOT_EXISTS            = "商品信息不存在";
    /**商品数量不能为空*/
    public static final String  GOODS_NUMBER_NULL           = "商品数量不能为空";
    /**商品数量不能小于1*/
    public static final String  GOODS_NUMBER_NOT_LESS_ONE   = "商品数量不能小于1";
    /**图片文件不能为空*/
    public static final String  PICTURE_FILE_IS_NULL        = "图片文件不能为空";
    /**商品名称不能为空*/
    public static final String  GOODS_NAME_NULL             = "商品名称不能为空";
    /**商品默认单价不能为空*/
    public static final String  GOODS_DEFAULT_PRICE_NULL    = "商品默认单价不能为空";
    /**商品副标题不能为空*/
    public static final String  GOODS_SUBJECT_NAME_NULL     = "商品副标题不能为空";
    /**商品排序不能为空*/
    public static final String  GOODS_ORDER_NULL            = "商品排序不能为空";
    /**商品详情描述不能为空*/
    public static final String  GOODS_DETAIL_DESC_NULL      = "商品详情描述不能为空";
    /**上传文件失败*/
    public static final String  UPLOAD_FILE_FAILURE         = "上传文件失败";

    /**该商品已下架*/
    public static final String  GOODS_STATUS_DOWN_EXIST     = "该商品已下架";

    /**操作的商品对象为空*/
    public static final String  GOODS_NULL                  = "操作的商品对象为空";

    /**未删除*/
    public static final Byte    GOODSPRICESIZE_ISNOT_DELETE = 0;
    /**已删除*/
    public static final Byte    GOODSPRICESIZE_IS_DELETE    = 1;

    private Integer             id;
    /**商品名称*/
    private String              goodsName;
    /**商品副标题*/
    private String              goodsSubName;
    /**商品编码*/
    private String              goodsCode;
    /**商品展示图*/
    private String              goodsPic;
    /**商品白底图*/
    private String              goodsBasePic;
    /**分类ID*/
    private Integer             goodsCategoryId;
    /**商品默认显示单价*/
    private Double              goodsDefalutPrice;
    /**商品类型(0:商品 1:配件)*/
    private Byte                goodsType;
    /**商品状态(0:未上架 1:已上架  2:已下架)*/
    private Byte                goodsStatus;
    /**商品排序*/
    private Integer             goodsOrder;
    /**创建时间*/
    private Date                createdDate;
    /**创建人*/
    private String              createdName;
    /**修改时间*/
    private Date                updatedDate;
    /**修改人*/
    private String              updatedName;
    /**商品英文名称*/
    private String              goodsEnName;
    /**分类名称*/
    private String              categoryName;
    /**商品特性*/
    private Byte                goodsLable;


	/***************************************************************/
    /**商品描述url*/
    private String              goodsDescUrl;
    /**商品价格*/
    private Double              goodsPrice;
    /**商品尺寸*/
    private String              goodsSize;
    /**商品重量*/
    private String              goodsWeight;

    /**商品特殊属性ID*/
    private Integer             goodsPriceSizeId;
    /**购买数量*/
    private Integer             goodsNumber;
    /**小计*/
    private Double              subTotal;
    /**购物车ID*/
    private Integer             goodsCarId;

    private Byte                isDelete;

    private String              goodsDescHtml;
    
    /**商品甜度*/
    private Integer				goodsDefalutSweet;
    
    /**商品默认规格*/
    private String 				goodsDefalutWeight;

    /**
     * 校验商品ID是否为空
     * @param goodsId
     */
    public static void validGoodsIdNull(Integer goodsId) {
        if (goodsId == null) {
            throw new ServiceException(GoodsModel.GOODS_ID_NULL);
        }
    }

    /**
     * 添加图片数据校验
     * @param files
     * @param goodsModel
     */
    public static void validateGoodsParam(List<MultipartFile> files, GoodsModel goodsModel) {
        if (goodsModel == null) {
            throw new ServiceException(GoodsModel.GOODS_NULL);
        }
        if (StringUtils.isEmpty(goodsModel.getGoodsName())) {
            throw new ServiceException(GoodsModel.GOODS_NAME_NULL);
        }
        if (goodsModel.getGoodsDefalutPrice() == null) {
            throw new ServiceException(GoodsModel.GOODS_DEFAULT_PRICE_NULL);
        }
        if (StringUtils.isEmpty(goodsModel.getGoodsSubName())) {
            throw new ServiceException(GoodsModel.GOODS_SUBJECT_NAME_NULL);
        }
        if (goodsModel.getGoodsOrder() == null) {
            throw new ServiceException(GoodsModel.GOODS_ORDER_NULL);
        }
        if (StringUtils.isEmpty(goodsModel.getGoodsDescHtml())) {
            throw new ServiceException(GoodsModel.GOODS_DETAIL_DESC_NULL);
        }
        if (goodsModel.getId() == null && files.isEmpty()) {
            for (MultipartFile multipartFile : files) {
                if (multipartFile.isEmpty()) {
                    throw new ServiceException(GoodsModel.PICTURE_FILE_IS_NULL);
                }
            }
        }
    }

    /**
     * 校验商品排序
     * @param list
     */
    public static void validGoodsOrder(List<GoodsModel> list) {
        for (GoodsModel goodsModel : list) {
            if (goodsModel.getGoodsOrder() == null) {
                throw new ServiceException(GoodsModel.GOODS_ORDER_NULL);
            }
            if (goodsModel.getId() == null) {
                throw new ServiceException(GoodsModel.GOODS_ID_NULL);
            }
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsSubName() {
        return goodsSubName;
    }

    public void setGoodsSubName(String goodsSubName) {
        this.goodsSubName = goodsSubName;
    }

    public String getGoodsCode() {
        return goodsCode;
    }

    public void setGoodsCode(String goodsCode) {
        this.goodsCode = goodsCode;
    }

    public String getGoodsPic() {
        return goodsPic;
    }

    public void setGoodsPic(String goodsPic) {
        this.goodsPic = goodsPic;
    }

    public String getGoodsBasePic() {
        return goodsBasePic;
    }

    public void setGoodsBasePic(String goodsBasePic) {
        this.goodsBasePic = goodsBasePic;
    }

    public Integer getGoodsCategoryId() {
        return goodsCategoryId;
    }

    public void setGoodsCategoryId(Integer goodsCategoryId) {
        this.goodsCategoryId = goodsCategoryId;
    }

    public Double getGoodsDefalutPrice() {
        return goodsDefalutPrice;
    }

    public void setGoodsDefalutPrice(Double goodsDefalutPrice) {
        this.goodsDefalutPrice = goodsDefalutPrice;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedName() {
        return createdName;
    }

    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public String getUpdatedName() {
        return updatedName;
    }

    public void setUpdatedName(String updatedName) {
        this.updatedName = updatedName;
    }

    public Byte getGoodsStatus() {
        return goodsStatus;
    }

    public void setGoodsStatus(Byte goodsStatus) {
        this.goodsStatus = goodsStatus;
    }

    public Integer getGoodsOrder() {
        return goodsOrder;
    }

    public void setGoodsOrder(Integer goodsOrder) {
        this.goodsOrder = goodsOrder;
    }

    public String getGoodsDescUrl() {
        return goodsDescUrl;
    }

    public void setGoodsDescUrl(String goodsDescUrl) {
        this.goodsDescUrl = goodsDescUrl;
    }

    public Double getGoodsPrice() {
        return goodsPrice;
    }

    public void setGoodsPrice(Double goodsPrice) {
        this.goodsPrice = goodsPrice;
    }

    public String getGoodsSize() {
        return goodsSize;
    }

    public void setGoodsSize(String goodsSize) {
        this.goodsSize = goodsSize;
    }

    public String getGoodsWeight() {
        return goodsWeight;
    }

    public void setGoodsWeight(String goodsWeight) {
        this.goodsWeight = goodsWeight;
    }

    public Byte getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(Byte goodsType) {
        this.goodsType = goodsType;
    }

    public Integer getGoodsPriceSizeId() {
        return goodsPriceSizeId;
    }

    public void setGoodsPriceSizeId(Integer goodsPriceSizeId) {
        this.goodsPriceSizeId = goodsPriceSizeId;
    }

    public Integer getGoodsNumber() {
        return goodsNumber;
    }

    public void setGoodsNumber(Integer goodsNumber) {
        this.goodsNumber = goodsNumber;
    }

    public Double getSubTotal() {
        return subTotal;
    }

    public void setSubTotal(Double subTotal) {
        this.subTotal = subTotal;
    }

    public Integer getGoodsCarId() {
        return goodsCarId;
    }

    public void setGoodsCarId(Integer goodsCarId) {
        this.goodsCarId = goodsCarId;
    }

    public Byte getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(Byte isDelete) {
        this.isDelete = isDelete;
    }

    public String getGoodsDescHtml() {
        return goodsDescHtml;
    }

    public void setGoodsDescHtml(String goodsDescHtml) {
        this.goodsDescHtml = goodsDescHtml;
    }

    public String getGoodsEnName()
	{
		return goodsEnName;
	}

	public void setGoodsEnName(String goodsEnName)
	{
		this.goodsEnName = goodsEnName;
	}
	
    public String getCategoryName()
	{
		return categoryName;
	}

	public void setCategoryName(String categoryName)
	{
		this.categoryName = categoryName;
	}
	
	public Byte getGoodsLable()
	{
		return goodsLable;
	}

	public void setGoodsLable(Byte goodsLable)
	{
		this.goodsLable = goodsLable;
	}

	public Integer getGoodsDefalutSweet()
	{
		return goodsDefalutSweet;
	}

	public void setGoodsDefalutSweet(Integer goodsDefalutSweet)
	{
		this.goodsDefalutSweet = goodsDefalutSweet;
	}

	public String getGoodsDefalutWeight()
	{
		return goodsDefalutWeight;
	}

	public void setGoodsDefalutWeight(String goodsDefalutWeight)
	{
		this.goodsDefalutWeight = goodsDefalutWeight;
	}

	@Override
    public String toString() {
        return "GoodsDO [id=" + id + ", goodsName=" + goodsName + ", goodsSubName=" + goodsSubName
               + ", goodsCode=" + goodsCode + ", goodsPic=" + goodsPic + ", goodsBasePic="
               + goodsBasePic + ", goodsCategoryId=" + goodsCategoryId + ", goodsDefalutPrice="
               + goodsDefalutPrice + ", goodsEnName=" + goodsEnName + ", categoryName=" + categoryName + ",goodsLable="+goodsLable+",createdDate=" + createdDate + ", createdName="
               + createdName + ", updatedDate=" + updatedDate + ", updatedName=" + updatedName
               + "]";
    }

}
